package com.yl.utils;

import com.yl.common.constant.HttpStatus;
import com.yl.common.core.page.TableDataInfo;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 工具类
 *
 * @author : y
 * @date : 2024/6/3 17:19
 */
public class CommonUtils {
    public static TableDataInfo getTableDataInfo() {
        TableDataInfo info = new TableDataInfo();
        info.setCode(HttpStatus.SUCCESS);
        info.setMsg("查询成功");
        info.setTotal(0);
        info.setRows(new ArrayList<>());
        return info;
    }
    public static String get10DigitTimestamp() {
        long currentTimeMillis = System.currentTimeMillis();
        String timestamp = String.valueOf(currentTimeMillis);
        return timestamp.substring(0, 10);
    }

    /**
     * 将Object对象里面的属性和值转化成Map对象
     *
     * @param obj
     * @return
     * @throws IllegalAccessException
     */
    public static Map<String, Object> objectToMap(Object obj) throws IllegalAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        Class<?> clazz = obj.getClass();
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            Object value = field.get(obj);
            map.put(fieldName, value);
        }
        return map;

    }
    /**
     * 获取随机数
     *
     * @author : y
     * @date : 2024/6/3 17:20
     */
    public static String getUUid(int num) {
        UUID uuid = UUID.randomUUID();
        // 去掉间隔符
        String replace = uuid.toString().replace("-", "");
        String randomNumber = replace.substring(0, num);
        return randomNumber;
    }
}
